using System;
using System.Collections.Generic;
using System.Linq;
namespace DIS_WEB_Client.Controllers
{
	#region using
	using System.Web.Mvc;
	using DIS_WEB_Client.ViewModels;
	using DIS_WEB_Client.Helpers;
	using System.Web.Security;
    using DIS_Web_Client.DIS_WS_BusinessLayer;
	#endregion
	public partial class AdminController: BaseController
	{
        public ActionResult SelectDailyReport()
        {
            var idchemistwarehouse = BusService.Instance.ChemistWareHouse_SelectAll().First(n => n.Name.ToUpper().Contains("ONLINE")).ID;
            var data = new DataTransferViewModel
            {
                IDChemistWareHouse = idchemistwarehouse,
                EnumViewModelType = EnumViewModel.ADMIN_DAILYREPORT,
            };
            return View(CreateViewModel(data));
        }

		public ActionResult EditDailyReport(int page, int id)
		{
			var data = new DataTransferViewModel
			{
				EnumViewModelType = EnumViewModel.ADMIN_DAILYREPORT,
				CurrentPage = page,
				IntID = id
			};
			return PartialView("Templates/TH_EditDailyReport", CreateViewModel(data));
		}

		public ActionResult CancelEditingDailyReport(int page)
		{
			var data = new DataTransferViewModel
			{
				EnumViewModelType = EnumViewModel.ADMIN_DAILYREPORT,
				CurrentPage = page
			};
			return PartialView("Templates/TH_ListDailyReport", CreateViewModel(data));
		}

		[ValidateInput(false)]
		[AcceptVerbs(HttpVerbs.Post)]
		public ActionResult InsertDailyReport(FormCollection forms)
		{
            var idchemistwarehouse = BusService.Instance.ChemistWareHouse_SelectAll().First(n => n.Name.ToUpper().Contains("ONLINE")).ID; ;
			string note = forms.GetValues("DailyReport_Note")[0];
			var newItem = new DailyReportDTO
			{
				IDChemistWareHouse = idchemistwarehouse,
                ReportDate = DateTime.Now,
				Note = note
			};
			var result = BusService.Instance.DailyReport_Insert(newItem);
			var data = new DataTransferViewModel
			{
				IDChemistWareHouse = idchemistwarehouse,
				EnumViewModelType = EnumViewModel.ADMIN_DAILYREPORT,
				InfoText = result ? "New item has been added" : "Cannot insert new item"
			};
			return View("SelectDailyReport", CreateViewModel(data));
		}

        public ActionResult DetailOfDailyReport(int id)
        {
            var data = new DataTransferViewModel
            {
                EnumViewModelType = EnumViewModel.ADMIN_DETAILOF_DAILYREPORT,
                IntID = id
            };
            return View(CreateViewModel(data));
        }
	}
}